Fix frozendict constructor: drop the argument-less __init__ (#15985)#15989
Merged
hauntsaninja merged 2 commits intoJul 8, 2026
Conversation
frozendict has __new__ overloads for keyword arguments, a mapping and an iterable of pairs, but also declared 'def __init__(self) -> None: ...', so type checkers rejected 'frozendict(a=1)' etc. with 'Expected 0 positional arguments'. Remove the redundant __init__ (like other __new__-constructed builtins) so the __new__ overloads govern construction. Added a test case.
This comment has been minimized.
This comment has been minimized.
hauntsaninja
reviewed
Jul 8, 2026
| from typing import Any | ||
| from typing_extensions import assert_type | ||
|
|
||
| # Regression test for gh-15985: ``frozendict`` can be constructed from keyword |
Collaborator
There was a problem hiding this comment.
might need an if sys.version_info >= (3, 15): top level block
Contributor
Author
There was a problem hiding this comment.
Good catch — done. Wrapped the assertions in an if sys.version_info >= (3, 15): block (matching check_exception_group-py311.py), so the file also type-checks cleanly on earlier target versions instead of tripping on the undefined frozendict name.
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15985.
The new (3.15)
frozendictbuiltin has__new__overloads for keyword arguments, a mapping, and an iterable of pairs, but the stub also declared:Because type checkers validate a constructor call against both
__new__and__init__, that argument-less__init__madefrozendict(a=1),frozendict({...}), andfrozendict([...])all fail with "Expected 0 positional arguments" / "Too many arguments".Removing the redundant
__init__lets the__new__overloads govern construction (matching other__new__-constructed builtins liketuple/frozenset, which don't declare a restrictive__init__).Added
check_frozendict-py315.pycovering the keyword / mapping / iterable / mixed forms; it fails onmainand passes with this change.tests/mypy_test.py stdlib/builtins.pyisucceeds.Disclosure: prepared with AI assistance; reviewed and verified locally.